package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.Admin;
import com.atguigu.entity.Role;
import com.atguigu.mapper.AdminMapper;
import com.atguigu.service.AdminService;
import com.atguigu.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @Author: 翟文海
 * @Date: 2022/10/26/026 13:48
 * @Version: 1.0
 * @Description:
 **/
@Service(interfaceClass = AdminService.class)
public class AdminServiceImpl extends BaseServiceImpl<Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private RoleService roleService;


    @Override
    protected BaseMapper<Admin> getMapper() {
        return adminMapper;
    }

    @Override
    public List<Admin> findAdminListNotAssignHouseId(Long id) {
       return adminMapper.findAdminListNotAssignHouseId(id);
    }

    @Override
    public Admin getByUsername(String s) {
        return adminMapper.getByUsername(s);
    }

    @Override
    public void insert(Admin admin) {
        Admin dbRole = adminMapper.getByUsername(admin.getUsername());
        if (dbRole != null) {
            throw new RuntimeException("用户名已经存在，不能重复添加");
        }

        adminMapper.insert(admin);
    }
}
